package mapreduce;

import java.util.Comparator;

/**
 * Comparator class for Point
 * Data structure
 */

public class PointComparator implements Comparator<Point> {

	/**
	 * @param p1
	 * @param p2
	 * @return -1 If p1 occurs before p2
	 * 0 if both the points are same
	 * and +1 if p2 occurs before p1
	 */
	public int compare(Point p1, Point p2) {
		if (p1.getx() > p2.getx()) {
			return 1;
		} else if (p1.getx() == p2.getx()) {
			if (p1.gety() > p2.gety()) {
				return 1;
			} else if (p1.gety() == p2.gety()) {
				return 0;
			} else {
				return -1;
			}
		} else {
			return -1;
		}
	}

	public boolean areEqual(Point p1, Point p2)
	{
		return (compare(p1,p2)==0);
	}
}